﻿using Sidvall.UI.Dialogs;
using System;
using System.Threading.Tasks;
using Windows.Storage.Pickers;

namespace Sidvall.UI.Uwp.Dialogs
{
    public class FolderDialog : IFolderDialog
    {
        #region Public Members

        #region OpenFolderAsync

        public async Task OpenFolderAsync(OpenFolderDialogContext context)
        {
            if (context == null)
                throw new System.ArgumentNullException(nameof(context));

            var dialog = new FolderPicker();
            dialog.FileTypeFilter.Add("*");
            dialog.SuggestedStartLocation = PickerManager.GetPickerLocationId(null);
            dialog.ViewMode = PickerManager.GetPickerViewMode(null);
            var folder = await dialog.PickSingleFolderAsync();
            if (folder != null)
                context.SelectedPath = "?" + Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(folder);
        }

        #endregion

        #endregion
    }
}
